<?php


namespace app\common;

use think\exception\ValidateException;
use think\Validate;

/**
 * 校验基类
 * Class BaseValidate
 * @package app\common
 */
class BaseValidate extends Validate
{
    /**
     * 校验参数后返回一个数组
     * @return array
     */
    public function validateParam():array {
        $param = $this->request->param();
        foreach ($param as $key=>$value){
            if(!array_key_exists($key, $this->rule) || $value === "" || $value===null) {
                unset($param[$key]);
            }
        }
        $bool = $this->check($param);
        if (!$bool) {
            throw new ValidateException($this->getError());
        }
        return $param;
    }
}